package cn.kgc.vuehangbanhou.service;

import cn.kgc.vuehangbanhou.mapper.FlightMapper;
import cn.kgc.vuehangbanhou.pojo.Flight;
import cn.kgc.vuehangbanhou.pojo.FlightExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FlightServiceImpl implements FlightService {
    @Resource
    FlightMapper flightMapper;
    @Override
    public List<Flight> sele(Integer qifei, Integer daoda) {
        List<Flight> flights;
        if(qifei!=0&&daoda!=0){
        FlightExample example=new FlightExample();
        FlightExample.Criteria criteria = example.createCriteria();
        criteria.andDeparturecityEqualTo(qifei);
        criteria.andArrivalcityEqualTo(daoda);
         flights = flightMapper.selectByExample(example);
    }else{
        flights = flightMapper.selectByExample(null);
    }
        return flights;
    }

    @Override
    public Integer add(Flight flight) {
        return flightMapper.insert(flight);
    }
}
